package com.lagou.controller;

import com.lagou.pojo.Article;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Calendar;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/index")
    public ModelAndView toIndex(ModelAndView modelAndView, @RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
                                @RequestParam(value = "pageSize", defaultValue = "1") int pageSize){
        // 接收参数，如果当前分页参数没有参数  那么将进行0，2，如果有参数将获取到值进行传参
        Page<Article> page = articleService.findAll(pageNum,pageSize);

        // 设置前台返回数据
        List<Article> content = page.getContent();
       modelAndView.addObject("content", content);
       modelAndView.addObject("page", page);
       modelAndView.setViewName("client/index");
       return modelAndView;
    }
}
